/*
######################################################################################################
#                                                                                                    # 
#	This Class contain local functions used in current site
#                                                                                                    #	                                                                                                 # 
#	Author: Sharvan                                                                             #     
#	Date: 16/03/06                                                                                   # 
#	                                                                                                 # 
######################################################################################################
 */
using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Web.SessionState;
using System.Web.Compilation;
using System.IO;
using SiteManager;
using System.Data.SqlClient;

/// <summary>
/// Summary description for General
/// </summary>
public class localFunction 
{
    public readonly  static string DOCTORCOOKIE = "findadocdoc";
    public readonly static string PATIENTCOOKIE = "findadocp";
    public readonly static string DENTISTCOOKIE = "findadocdentist";

    HttpRequest Request;
    HttpResponse Response;
	public localFunction()
	{ 
        Request = HttpContext.Current.Request;
        Response = HttpContext.Current.Response;
		//
		// TODO: Add constructor logic here
		//
	}
    /// <summary>
    /// to Check wheater a doctor is looged in
    /// </summary>
    /// <returns></returns>
    public bool checkDoctorLogin(bool Redirect)
    {

        // Session["DoctorType"] CHECK ADDED 
        // DATE 15TH FEB 2008
        if (HttpContext.Current.Session["userID"].ToString().Trim() != "" && HttpContext.Current.Session["userType"].ToString() == "Doctor" && HttpContext.Current.Session["DoctorType"].ToString().ToUpper() == "Doctor".ToUpper())
        {
            return true;
        }
        //else if (HttpContext.Current.Session["userID"].ToString().Trim() != "" && HttpContext.Current.Session["userType"].ToString() == "Dentist")
        //{
        //    HttpContext.Current.Response.Redirect(HttpContext.Current.Session["strHttp"] + "dentist/dentistContent.aspx"); 
        //    return true;
        //}
        else
        {

            if (Redirect)
            {
                HttpContext.Current.Response.Redirect(HttpContext.Current.Session["strHttps"] + "doctor/doctorlogin.aspx?fromPg=" + HttpContext.Current.Request.Url);
            }
            return false;
        }
    }
    /// <summary>
    /// TO CHECK IF A DENTIST IS LOOGED IN
    /// </summary>
    /// <returns></returns>
    /// <remarks>
    /// AUTHOR  : KAJAL
    /// DATE    : 8 JUNE 2007
    /// </remarks>
    public bool checkDentistLogin(bool Redirect)
    {
        // Session["DoctorType"] CHECK ADDED
        // DATE 15TH FEB 2008
        if (HttpContext.Current.Session["userID"].ToString().Trim() != "" && HttpContext.Current.Session["userType"].ToString() == "Doctor" && HttpContext.Current.Session["DoctorType"].ToString().ToUpper() == "Dentist".ToUpper())
        {
            if (HttpContext.Current.Session["DOCTORTYPE"] != null)
            {
                if (HttpContext.Current.Session["DOCTORTYPE"].ToString().ToUpper() == "DENTIST")
                {
                    return true;
                }
                else
                {
                    return false;
                }
            }
            else
            {
                return false;
            }
        }
        else
        {

            if (Redirect)
            {
                HttpContext.Current.Response.Redirect(HttpContext.Current.Session["strHttps"] + "dentist/dentistlogin.aspx?fromPg=" + HttpContext.Current.Request.Url);
            }
            return false;
        }
    }

    /// <summary>
    /// To Logoff a dentist
    /// </summary>
    public void logOffDoctor()
    {
        HttpContext.Current.Session["userID"] = "";
        HttpContext.Current.Session["userType"] = "";
        HttpContext.Current.Session["pageFromOrAction"] = "";
        HttpContext.Current.Session["LoginName"] = "";
        HttpContext.Current.Session["UserEmail"] = "";
        HttpContext.Current.Session["DentistDoctorEmail"] = "";//Added for Face Page
        HttpContext.Current.Response.Redirect(HttpContext.Current.Session["strHttps"] + "doctor/doctorlogin.aspx");
    }

    /// <summary>
    /// to Logoff a doctor
    /// </summary>
    public void logOffDentist()
    {
       HttpContext.Current.Session["userID"] = "";
       HttpContext.Current.Session["userType"] = "";
       HttpContext.Current.Session["pageFromOrAction"] = "";
       HttpContext.Current.Session["LoginName"] = "";
       HttpContext.Current.Session["UserEmail"] = "";
       HttpContext.Current.Session["DOCTORTYPE"] = "";
       HttpContext.Current.Session["DentistDoctorEmail"] = "";//Added for Face Page
       HttpContext.Current.Response.Redirect(HttpContext.Current.Session["strHttps"] + "dentist/dentistlogin.aspx");
    }
    /// <summary>
    /// 
    /// </summary>
    /// <param name="Redirect"></param>
    /// <returns></returns>
    public bool checkUserLogin(bool Redirect)
    {
        //if (HttpContext.Current.Session["userID"].ToString().Trim() != "")

        if ((HttpContext.Current.Session["userID"].ToString().Trim() != "")
            && (HttpContext.Current.Session["userType"].ToString().ToUpper() != "DOCTOR"))
        {
            return true;
        }
        else
        {
            if (Redirect)
                HttpContext.Current.Response.Redirect(HttpContext.Current.Session["strHttp"] + "default.aspx?fromPg=" + HttpContext.Current.Request.Url);
            return false;
        }
    }
    /// <summary>
    /// 
    /// </summary>
    /// <param name="Redirect"></param>
    /// <returns></returns>
    public bool checkDoctorandDentisLogin(bool Redirect)
    {
        //if (HttpContext.Current.Session["userID"].ToString().Trim() != "")

        if ((HttpContext.Current.Session["userID"].ToString().Trim() != "")
            && ((HttpContext.Current.Session["userType"].ToString().ToUpper() != "DOCTOR") || HttpContext.Current.Session["userType"].ToString().ToUpper() != "DENTIST"))
        {
            return true;
        }
        else
        {
            if (Redirect)
                HttpContext.Current.Response.Redirect(HttpContext.Current.Session["strHttp"] + "default.aspx?fromPg=" + HttpContext.Current.Request.Url);
            return false;
        }
    }
    /// <summary>
    /// 
    /// </summary>
    public void logOffUser()
    {
        HttpContext.Current.Session["userID"] = "";
        HttpContext.Current.Session["userType"] = "";
        HttpContext.Current.Session["pageFromOrAction"] = "";
        HttpContext.Current.Session["LoginName"] = "";
        HttpContext.Current.Session["UserEmail"] = "";
        HttpContext.Current.Session["DentistDoctorEmail"] = "";//Added for Face Page
        HttpContext.Current.Response.Redirect(HttpContext.Current.Session["strHttp"] + "default.aspx");
    }

    public bool checkPatientLogin(bool Redirect)
    {
      
        if ((HttpContext.Current.Session["userID"].ToString().Trim() != "")
            && (HttpContext.Current.Session["userType"].ToString().ToUpper() == "SITEUSER"))
        {
            return true;
        }
        else
        {
            if (Redirect)
                HttpContext.Current.Response.Redirect(HttpContext.Current.Session["strHttp"] + "default.aspx?fromPg=" + HttpContext.Current.Request.Url);
            return false;
        }
    }


    #region Thumbnail
    public byte[] getThumbnaleImage(byte[] img, int maxWidth, int maxHeight)
    {
        MemoryStream ms = new MemoryStream(img, 0, img.Length);
        ms.Write(img, 0, img.Length);

        
        double imgHeight, imgWidth;
        //Response.Write(imgName) ;
     //   s = Server.MapPath(imgName);
        //Response.Write("<br>"+s);
        System.Drawing.Image currentImage = System.Drawing.Image.FromStream(ms,true);
        imgHeight = currentImage.Height;
        imgWidth = currentImage.Width;
        if (imgWidth > maxWidth | imgHeight > maxHeight)
        {
            double deltaWidth = imgWidth - maxWidth;
            double deltaHeight = imgHeight - maxHeight;
            double scaleFactor;
            if (deltaHeight > deltaWidth)
                scaleFactor = maxHeight / imgHeight;
            else
                scaleFactor = maxWidth / imgWidth;
            imgWidth *= scaleFactor;
            imgHeight *= scaleFactor;
        }

        MemoryStream oThumb = new MemoryStream();
        currentImage.GetThumbnailImage(Convert.ToInt32(imgWidth), Convert.ToInt32(imgHeight), null, IntPtr.Zero).Save(oThumb,System.Drawing.Imaging.ImageFormat.Gif);

        byte[] bThumb = oThumb.ToArray();
                
        currentImage.Dispose();
        oThumb = null;
        ms = null;
        return bThumb;
    }

    #endregion


    #region Cookies
    public void rememberMe(string cookiename,string userName,string Pass)
    {
        //To store Username/Password in cookies
       // HttpCookie cookie = new HttpCookie(cookiename);
        CreateCookie(userName, Pass,cookiename);
    }

    public void RemoveCookie(string cookiename)
    {        
            if (Request.Cookies[cookiename] != null)
            {
                Response.Cookies[cookiename].Expires = DateTime.Now.AddYears(-30);                
            }     
    }


    void CreateCookie(string username, string password,string cookiename)
    {
        //  Check if browser accepts cookies.
                if (Request.Browser.Cookies)
        {
            //  If the cookie does not exist...
            if (Request.Cookies[cookiename] == null)
            {
                //Create the cookie.
                HttpCookie LoginCheck = new HttpCookie(cookiename);
                LoginCheck.Values["UserName"] = username;
                LoginCheck.Values["Password"] = password;
                //Set the expiration 
                LoginCheck.Expires = DateTime.Now.AddDays(30);
                //Add to cookies collection.
                Response.Cookies.Add(LoginCheck);
            }
            else
            {
                Response.Cookies[cookiename].Values["UserName"] = username;
                Response.Cookies[cookiename].Values["Password"] = password;
                Response.Cookies[cookiename].Expires = DateTime.Now.AddDays(30);
            }
        }
        else
        {
            //lblMsg.Text = "Your browser does not accept cookies.";            
            string err = "<script>alert('Your browser does not accept cookies.') </script>";
            Response.Write(err);
        }
    }

  public  void ReadCookie(string cookiename,out string username,out string password,out bool check)
    {
        username = "";
        password = "";
        check = false;
        if (Request.Cookies[cookiename] != null)
        {
            HttpCookie LoginCheck = Request.Cookies[cookiename];
            check = true;
            username = LoginCheck.Values["UserName"];
            password = LoginCheck.Values["Password"];
            if(username!="" &&password !="") 
            rememberMe(cookiename, username, password);
        }
    }
    #endregion

    #region QueryString Functions
    
    public void GetDrInfo(Boolean isLogin)
    {
        Manager obj = new Manager(true,"ConnectionString");
        SqlParameter[] sqlparam = new SqlParameter[1];
        sqlparam[0] = new SqlParameter("@Id", HttpContext.Current.Session["userID"]);
        SqlDataReader dr;
        dr = obj.ExecuteQuery("ReturnQuerystringVal_Doctor", sqlparam);
        if (dr.Read())
        {
           // string qString = "Specialty=" + dr["specialityName"] + "&Subspecialty=" + dr["SubSpec"] + "&State=" + dr["state"] + "&city=" + dr["city"] + "&zip=" + dr["zipcode"];
            string specName = dr["specialityName"].ToString();
            string SubSpecName = dr["SubSpec"].ToString();
            string state = dr["state"].ToString();
            string city = dr["city"].ToString();
            string zipcode = dr["zipcode"].ToString();
            dr.Close();

            if (isLogin)
            {
                //Added By Wahaj Khan April 30 2012
                if (HttpContext.Current.Session["FacePageURL"] != null)
                {

                    if (HttpContext.Current.Session["FacePageURL"].ToString().Trim() != "")
                    {
                        string strFacePage = HttpContext.Current.Session["FacePageURL"].ToString().Trim();
                        HttpContext.Current.Session["FacePageURL"] = null;
                        Response.Redirect(strFacePage,true);
                    }
                }

                //else if (HttpContext.Current.Session["DoctorDetailUrl"] != null)
                //{
                //    if (HttpContext.Current.Session["DoctorDetailUrl"].ToString().Trim() != "")
                //    {
                //        string strDoctorDetail = HttpContext.Current.Session["DoctorDetailUrl"].ToString().Trim();
                //        HttpContext.Current.Session["DoctorDetailUrl"] = null;
                //     // HttpContext.Current.Session["userID"] = "drLogin";
                //        Response.Redirect(strDoctorDetail, true);
                //    }
                // }
                  
               else //if (Session["FacePageURL"] == null)
                    //Added By Wahaj Khan April 30 2012
                    HttpContext.Current.Response.Redirect(HttpContext.Current.Session["strHttps"] + "doctor/doctorcontent.aspx?" + FormatURL(specName, SubSpecName, state, city, zipcode, false));
            }
            else
            {
                ////Old before applying New URL formate at 15/07/08
                //    HttpContext.Current.Response.Redirect(HttpContext.Current.Session["strHttp"] + "doctor/DoctorsDetails.aspx?id=" + HttpContext.Current.Session["userID"] + FormatURL(specName, SubSpecName, state, city, zipcode, true));
                ////Old End

                //New at 15/07/08                
                HttpContext.Current.Response.Redirect(HttpContext.Current.Session["strHttp"] + "doctors/" + URLFormat(specName, state, city, true) + "/" + HttpContext.Current.Session["userID"] + "-" + HttpContext.Current.Session["LoginName"] + ".aspx");

            }
        }
        dr.Close();
        }

    public void GetDentInfo(Boolean isLogin)
    {
        Manager obj = new Manager(true,"ConnectionString");
        SqlParameter[] sqlparam = new SqlParameter[1];
        sqlparam[0] = new SqlParameter("@Id", HttpContext.Current.Session["userID"]);
        SqlDataReader dr;
        dr = obj.ExecuteQuery("ReturnQuerystringVal_Dentist", sqlparam);
        if (dr.Read())
        {
   //         string qString = "Specialty=" + dr["specialityName"] + "&Subspecialty=" + dr["SubSpec"] + "&State=" + dr["state"] + "&city=" + dr["city"] + "&zip=" + dr["zipcode"];
            string specName = dr["specialityName"].ToString();
            string SubSpecName = dr["SubSpec"].ToString();
            string state = dr["state"].ToString();
            string city = dr["city"].ToString();
            string zipcode = dr["zipcode"].ToString();
            dr.Close();

            if (isLogin)
            {
                //Added By Wahaj Khan April 30 2012
                if (HttpContext.Current.Session["FacePageURL"] != null)
                {

                    if (HttpContext.Current.Session["FacePageURL"].ToString().Trim() != "")
                    {
                        string strFacePage = HttpContext.Current.Session["FacePageURL"].ToString().Trim();
                        HttpContext.Current.Session["FacePageURL"] = null;
                        Response.Redirect(strFacePage, true);
                    }
                }
                else //if (Session["FacePageURL"] == null)
                    //Added By Wahaj Khan April 30 2012
                    HttpContext.Current.Response.Redirect(HttpContext.Current.Session["strHttps"] + "dentist/dentistcontent.aspx?" + FormatURL(specName, SubSpecName, state, city, zipcode, false));
            }
            else
            {
                ////Old before applying New URL formate at 16/07/08
                //HttpContext.Current.Response.Redirect(HttpContext.Current.Session["strHttp"] + "dentist/dentistdetails.aspx?id=" + HttpContext.Current.Session["userID"] + FormatURL(specName, SubSpecName, state, city, zipcode, true));
                ////END

                // New at 16/07/08
                HttpContext.Current.Response.Redirect(HttpContext.Current.Session["strHttp"] + "dentists/" + URLFormat(specName, state, city, true) + "/" + HttpContext.Current.Session["userID"] + "-" + HttpContext.Current.Session["LoginName"] + ".aspx");

            }
        }
        dr.Close();
    }

    #endregion

    #region URL formatting
    /// <summary>
    /// Function returns formatted querystring
    /// </summary>
    /// <param name="Specialty">Specialty Name</param>
    /// <param name="Subspecialty">Sub Specialty Name</param>
    /// <param name="State">State Name</param>
    /// <param name="City">City Name</param>
    /// <param name="Zip">Zipcode</param>
    /// <param name="isSuffix">True, if returned value will be suffixed to existing keys else False</param>
    /// <returns></returns>
    /// Created By: Deepak
    /// Creation Date: 11th Feb 2008
  
    public string FormatURL(object Specialty, object Subspecialty, object State, object City, object Zip, Boolean isSuffix)
    {
        

        string Qstring = string.Empty;
        if (Specialty.ToString() != "")
            //ADDED BY RANJEET TO REPLACE THESE CHARACTERS ()&[],\/-  WITH A BLANK SPACE 

            

            Specialty = Specialty.ToString().Trim().Replace(" ", "_");
            Specialty = Specialty.ToString().Trim().Replace("(", "_");
            Specialty = Specialty.ToString().Trim().Replace(")", "_");
            Specialty = Specialty.ToString().Trim().Replace("&", "_");
            Specialty = Specialty.ToString().Trim().Replace("[", "_");
            Specialty = Specialty.ToString().Trim().Replace("]", "_");
            Specialty = Specialty.ToString().Trim().Replace("\\", "_");
            Specialty = Specialty.ToString().Trim().Replace("//", "_");
            Specialty = Specialty.ToString().Trim().Replace("-", "_");
            Specialty = Specialty.ToString().Trim().Replace("___", "_");
            Specialty = Specialty.ToString().Trim().Replace("__", "_");

           
            
            //Qstring = Qstring + "&Specialty=" + Specialty.ToString().Trim().Replace(" ", "_");
            
                Qstring = Qstring + "&Specialty=" + Specialty.ToString().Trim();                        

        if (Subspecialty.ToString() != "")

            Subspecialty = Subspecialty.ToString().Trim().Replace(" ", "_");
            Subspecialty = Subspecialty.ToString().Trim().Replace("(", "_");
            Subspecialty = Subspecialty.ToString().Trim().Replace(")", "_");
            Subspecialty = Subspecialty.ToString().Trim().Replace("_&_", "_");
            Subspecialty = Subspecialty.ToString().Trim().Replace("[", "_");
            Subspecialty = Subspecialty.ToString().Trim().Replace("]", "_");
            Subspecialty = Subspecialty.ToString().Trim().Replace("\\", "_");
            Subspecialty = Subspecialty.ToString().Trim().Replace("//", "_");
            Subspecialty = Subspecialty.ToString().Trim().Replace("-", "_");
            Subspecialty = Subspecialty.ToString().Trim().Replace("___", "_");
            Subspecialty = Subspecialty.ToString().Trim().Replace("__", "_");            

            Qstring = Qstring + "&Subspecialty=" + Subspecialty.ToString().Trim();
            if (State.ToString() != "")
                Qstring = Qstring + "&State=" + State.ToString().Trim().Replace(" ", "_");
            if (City.ToString() != "")
                Qstring = Qstring + "&City=" + City.ToString().Trim().Replace(" ", "_");
            if (Zip.ToString() != "")
                Qstring = Qstring + "&Zip=" + Zip.ToString().Trim().Replace(" ", "_");                        

        if (!isSuffix)
            Qstring = Qstring.Substring(1);

        return Qstring;
    }

    public string GetDrInfoForBlog(object id)
    {
        Manager obj = new Manager(true,"ConnectionString");
        SqlParameter[] sqlparam = new SqlParameter[1];
        sqlparam[0] = new SqlParameter("@Id", id.ToString());
        SqlDataReader dr;
        dr = obj.ExecuteQuery("ReturnQuerystringVal_Doctor", sqlparam);
        if (dr.Read())
        {
            // string qString = "Specialty=" + dr["specialityName"] + "&Subspecialty=" + dr["SubSpec"] + "&State=" + dr["state"] + "&city=" + dr["city"] + "&zip=" + dr["zipcode"];
            string specName = dr["specialityName"].ToString();
            string SubSpecName = dr["SubSpec"].ToString();
            string state = dr["state"].ToString();
            string city = dr["city"].ToString();
            string zipcode = dr["zipcode"].ToString();
            dr.Close();

            return (FormatURL(specName, SubSpecName, state, city, zipcode, true));           
        }
        dr.Close();
        return "";
    }


    public string GetDentInfoForBlog(object id)
    {
        Manager obj = new Manager(true,"ConnectionString");
        SqlParameter[] sqlparam = new SqlParameter[1];
        sqlparam[0] = new SqlParameter("@Id", id.ToString());
        SqlDataReader dr;
        dr = obj.ExecuteQuery("ReturnQuerystringVal_Dentist", sqlparam);
        if (dr.Read())
        {
            // string qString = "Specialty=" + dr["specialityName"] + "&Subspecialty=" + dr["SubSpec"] + "&State=" + dr["state"] + "&city=" + dr["city"] + "&zip=" + dr["zipcode"];
            string specName = dr["specialityName"].ToString();
            string SubSpecName = dr["SubSpec"].ToString();
            string state = dr["state"].ToString();
            string city = dr["city"].ToString();
            string zipcode = dr["zipcode"].ToString();
            dr.Close();

            return (FormatURL(specName, SubSpecName, state, city, zipcode, true));
        }
        dr.Close();
        return "";
    }

    #endregion

    #region Cookie Function

    /// <summary>
    /// Create/Delete a cookie for user, if 'Remeber Me' is checked
    /// Author: Deepak
    /// Date: 16th Feb '08
    /// </summary>
    /// <param name="CookieName">Name of cookie, to create or delete</param>
    /// <param name="UserEmail">Email Id of User</param>
    /// <param name="Password">Password of User</param>
    /// <param name="SetCookie">True if New cookie is to be created, False if exisiting cookie is to be Deleted</param>
    /// <example>Cookie(localFunction.DOCTORCOOKIE, txtDocEmail.Text.Trim(), txtDocPass.Text.Trim(), true)</example>
    public void Cookie(string CookieType, string UserEmail, string Password, Boolean SetCookie)
    {
        
        if (SetCookie)
        {
            switch(CookieType.Trim())
            {
                case "findadocdoc":
                    rememberMe(localFunction.DOCTORCOOKIE, UserEmail, Password);
                    break;
                case "findadocp":
                    rememberMe(localFunction.PATIENTCOOKIE, UserEmail, Password);
                    break;
                case "findadocdentist":
                    rememberMe(localFunction.DENTISTCOOKIE, UserEmail, Password);
                    break;
                default:
                    //dostuff;
                    break;
            }

        }
        else
        {
            RemoveCookie(CookieType);
        }
    }

    #endregion

    public string DisplayAdBanner(string speciality, string subSpeciality)
    {
        string Category = string.Empty;
        string AdCode = "";

        if (speciality.ToString() != "")
            Category = speciality.ToString();
        else if (subSpeciality.ToString() != "")
            Category = subSpeciality.ToString();

       // context.Response.Write("BANNER CODE");

        if (Category != "")
        {
            Manager objMan = new SiteManager.Manager();
            string sql = "Select BannerCode from tblBannerCode where CategoryName='" + Category + "'";
            SqlDataReader dr = objMan.ExecuteQuery(sql);
            if (dr.Read())
            {
                AdCode = dr["BannerCode"].ToString();
            }
            dr.Close();
        }

        return AdCode;
    }

    /// <summary>
    /// Function returns formatted querystring
    /// </summary>
    /// <param name="Specialty">Specialty Name</param>   
    /// <param name="State">State Name</param>
    /// <param name="City">City Name</param>    
    /// <param name="isSuffix">True, if returned value will be suffixed to existing keys else False</param>
    /// <returns></returns>
    /// Created By: Ranjeet
    /// Creation Date: 15th july 2008

    public string URLFormat(object Specialty, object State, object City,Boolean isSuffix)
    {
        string Qstring = string.Empty;
        if (Specialty.ToString() != "")


      //ADDED BY RANJEET TO REPLACE THESE CHARACTERS ()&[],\/-  WITH A BLANK SPACE 



        Specialty = Specialty.ToString().Trim().Replace(" ", "_");
        Specialty = Specialty.ToString().Trim().Replace("(", "_");
        Specialty = Specialty.ToString().Trim().Replace(")", "_");
        Specialty = Specialty.ToString().Trim().Replace("&", "_");
        Specialty = Specialty.ToString().Trim().Replace("[", "_");
        Specialty = Specialty.ToString().Trim().Replace("]", "_");
        Specialty = Specialty.ToString().Trim().Replace("\\", "_");
        Specialty = Specialty.ToString().Trim().Replace("//", "_");
        Specialty = Specialty.ToString().Trim().Replace("-", "_");
        Specialty = Specialty.ToString().Trim().Replace("___", "_");
        Specialty = Specialty.ToString().Trim().Replace("__", "_");



        //Qstring = Qstring + "&Specialty=" + Specialty.ToString().Trim().Replace(" ", "_");

        //OLD before  apply new URL formate at 15/07/2008
            //Qstring = Qstring + "&Specialty=" + Specialty.ToString().Trim();
        //OLD END 15/07/2008



        

        ////OLD before  apply new URL formate at 15/07/2008

        //Qstring = Qstring + "&Subspecialty=" + Subspecialty.ToString().Trim();
        //if (State.ToString() != "")
        //    Qstring = Qstring + "&State=" + State.ToString().Trim().Replace(" ", "_");
        //if (City.ToString() != "")
        //    Qstring = Qstring + "&City=" + City.ToString().Trim().Replace(" ", "_");
        //if (Zip.ToString() != "")
        //    Qstring = Qstring + "&Zip=" + Zip.ToString().Trim().Replace(" ", "_");

        ////End at 15/07/2008

        //New Added at 15/07/08 to implement New URL formate


        if ((State.ToString() != "") || (State != null))
            Qstring = Qstring + State.ToString().Trim().Replace(" ", "_");
        if (City.ToString() != "")
            {
                if(Qstring !="")
                Qstring = Qstring + "/" + City.ToString().Trim().Replace(" ", "_");
                else
                Qstring = City.ToString().Trim().Replace(" ", "_");
            }
            if (Specialty.ToString() != "")
            {
                if (Qstring != "")
                Qstring = Qstring + "/" + Specialty.ToString().Trim();
                else
                Qstring = Specialty.ToString().Trim();
            }

        //End New Added 

        if (!isSuffix)
            Qstring = Qstring.Substring(1);

        return Qstring;
    }

    //Added at 17/07/08 for get doctor details by
        public string GetURLFormatById(int docid,string doctortype)
        {
            string docdetails = "";
            Manager mgrobj = new SiteManager.Manager();
            SqlDataReader dr=null;
            if (doctortype.ToString().Trim().ToUpper() == "DOCTOR")
            {
                dr = mgrobj.ExecuteQuery("select distinct d.*,s.name as speciality from tbl_doctors as d , tbl_Speciality as s where d.id=" + docid + " and s.id=d.SpecialityiD");
            }
            else if (doctortype.ToString().Trim().ToUpper() == "DENTIST")
            {
                dr = mgrobj.ExecuteQuery("select distinct d.*,sp.specialty as speciality from tbl_dentists as d , tbl_dentistspecialty as sp where d.id=" + docid + " and sp.id=d.specialityid");
            }
            if (dr.Read())
            {
                docdetails = URLFormat(dr["speciality"].ToString(), dr["state"].ToString(), dr["city"].ToString(), true);
                dr.Close();
            }
            return docdetails;
        }

    public string GetBlogTitle(string blogname)
    {
        string blogTitle = blogname;
        blogTitle = blogname.ToString().Trim().Replace(" ", "_");
        blogTitle = blogTitle.ToString().Trim().Replace("(", "_");
        blogTitle = blogTitle.ToString().Trim().Replace(")", "_");
        blogTitle = blogTitle.ToString().Trim().Replace("&", "_");
        blogTitle = blogTitle.ToString().Trim().Replace("[", "_");
        blogTitle = blogTitle.ToString().Trim().Replace("]", "_");
        blogTitle = blogTitle.ToString().Trim().Replace("\\", "_");
        blogTitle = blogTitle.ToString().Trim().Replace("//", "_");
        blogTitle = blogTitle.ToString().Trim().Replace("-", "_");
        blogTitle = blogTitle.ToString().Trim().Replace("___", "_");
        blogTitle = blogTitle.ToString().Trim().Replace("__", "_");
        blogTitle = blogTitle.ToString().Trim().Replace("?", "_");
        blogTitle = blogTitle.ToString().Trim().Replace(".", "_");
        return blogTitle;
    }



        private object _tempdocid;

        public object tempdocid
        {
            get
            {
                return _tempdocid;
            }
            set
            {
                _tempdocid = value;
            }
        }
}
